home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * Main.c *
- * *
- * -------------- The event handling routines -------------- *
- * *
- * Written by Casper Boon, August, 1992. *
- * *
- * © 1992 Casper Boon. *
- * *
- ************************************************************************/
-
- #include "LPD.H"
- #include "BackGrounder.H"
- #include "lpdProtos.H"
-
-
- void DoWindowActivate(WindowPtr wind, Boolean actv);
- void DoWindowUpdate(WindowPtr wind);
- void DoWindowClick(WindowPtr wind, Point point, integer modif);
- void DoWindowGrow(WindowPtr wind, Point point);
- void DoWindowZoom(WindowPtr wind, Boolean in);
- void DoWindowKey(WindowPtr wind, char c);
- LongWord GetSleep(void);
- void DoIdles(void);
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void main()
- {
- Initialise();
- UnloadSeg(Initialise);
-
- SetCursor(&arrow);
-
- if (!InitLPD())
- {
- SysBeep(5);
- Exit();
- }
-
- while (TRUE)
- MainEvents(everyEvent);
- }
-
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void WaitForEvent(integer evtMask, EventPtr event)
- {
- Boolean gotEvent;
-
- do {
- if (haveWaitEvnt)
- gotEvent = WaitNextEvent(evtMask, event, GetSleep(), cursRgn);
- else
- {
- SystemTask(); /* run drivers */
- gotEvent = GetNextEvent(evtMask, event);
- }
-
- CursorAdjust(event->where, cursRgn); /* update cursor */
-
- if (!gotEvent)
- {
- if (event->what == nullEvent)
- {
- IsDialogEvent(event); /* flick TE's in dialogs */
- DoIdles(); /* run the idle procedures */
- }
- }
- }
- while (!gotEvent);
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- integer MainEvents(integer evtMask)
- {
- integer part;
- WindowPtr window;
- EventRecord event;
-
- if (QuitRequest) Exit();
-
- WaitForEvent(evtMask, &event);
-
- if ( (event.what == keyDown) && (event.modifiers & cmdKey) )
- {
- if ( (event.message & 0x7F) == '.' )
- stopped = TRUE;
- else
- {
- SetMenuStates();
- DoCommand(MenuKey(event.message & 0x7F));
- }
- return TRUE;
- }
-
- if ( IsDialogEvent(&event) )
- {
- if ( HandleDEvent(&event) )
- return FALSE;
- }
-
- switch (event.what)
- {
- case mouseDown :
- part = FindWindow(event.where, &window);
- switch(part)
- {
- case inMenuBar :
- SetMenuStates();
- DoCommand(MenuSelect(event.where));
- break;
- case inSysWindow :
- SystemClick(&event, window);
- break;
- case inDrag :
- if (window == FrontWindow())
- DragWindow(window, event.where, &screenRect);
- else
- SelectWindow(window);
- break;
- case inGrow :
- if (window == FrontWindow())
- DoWindowGrow(window, event.where);
- else
- SelectWindow(window);
- break;
- case inGoAway :
- if ( TrackGoAway(window, event.where) )
- KillWindow((WindowPeek)window);
- break;
- case inContent :
- if ( window == FrontWindow() )
- DoWindowClick(window, event.where, event.modifiers);
- else
- SelectWindow(window);
- break;
- case inZoomIn :
- case inZoomOut :
- if ( TrackBox(window, event.where, part) )
- DoWindowZoom(window, (Boolean)(part == inZoomIn));
- break;
- }
- break;
- case keyDown:
- case autoKey:
- DoWindowKey(FrontWindow(), event.message & 0x7F);
- break;
- case activateEvt :
- DoWindowActivate((WindowPtr) event.message, event.modifiers & activeFlag);
- break;
- case updateEvt :
- window = (WindowPtr) event.message;
- BeginUpdate(window);
- SetPort(window);
- DoWindowUpdate(window);
- EndUpdate(window);
- break;
- case osEvt:
- switch ((event.message >> 24) & 0xFF) /* high byte of message */
- {
- case mouseMovedMessage:
- DoIdles();
- break;
- case suspendResumeMessage:
- inBackground = ((event.message & resumeFlag) == 0);
- if (inBackground) Banners_Down();
- else Banners_Back();
- DoWindowActivate(FrontWindow(), !inBackground);
- break;
- default:
- break;
- }
- break;
- default :
- break;
- }
-
- return FALSE;
- }
-
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void BeepNWait()
- {
- SysBeep(5);
- while ( !Button() );
- while ( Button() );
- }
-
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- integer KillWindow(WindowPeek wind)
- {
- return TRUE;
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- static void DoWindowActivate(WindowPtr wind, Boolean activ)
- {
- }
-
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- static void DoWindowUpdate(WindowPtr wind)
- {
- }
-
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- static void DoWindowClick(WindowPtr wind, Point point, integer modif)
- {
- }
-
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- static void DoWindowGrow(WindowPtr wind, Point point)
- {
- }
-
-
- /************************************************************************
- ************************************************************************/
- static void DoWindowKey(WindowPtr wind, char aChar)
- {
- }
-
-
- /************************************************************************
- ************************************************************************/
- static void DoWindowZoom(WindowPtr aWind, Boolean in)
- {
- }
-
- void doClose(void);
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void Exit()
- {
- QuitRequest = TRUE;
- if (!Quitable) return;
-
- doClose();
- FSClose(stdlog);
- FSClose(stderr);
- ExitToShell();
- }
-
- /************************************************************************
- ************************************************************************/
- void CursorAdjust(Point aPoint, RgnHandle crsRgn)
- {
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void UpdateEvents()
- {
- }
-
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- void DoIdles()
- {
- RunBackground();
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- LongWord GetSleep()
- {
- LongInt sleep = GetCaretTime();
-
- // if ( !inBackground )
- // sleep = 0x7F;
-
- return sleep;
- }
-
- /************************************************************************
- * *
- * *
- ************************************************************************/
- Boolean noMenus = FALSE;
- void WaitForState(integer *state)
- {
- Boolean quit_back = Quitable;
- EventRecord event;
-
- Quitable = FALSE;
- noMenus = TRUE;
-
- do {
- if ( !EventAvail(everyEvent, &event) )
- {
- if (haveWaitEvnt)
- WaitNextEvent(everyEvent, &event, GetSleep(), cursRgn);
- else
- SystemTask(); /* run drivers */
- }
- else
- MainEvents(everyEvent);
- RunBackground();
- }
- while (*state > 0);
-
- noMenus = FALSE;
- Quitable = quit_back;
- }
-